package com.wangsh.usersCenter.outer.service.impl;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.codec.digest.HmacAlgorithms;
import org.apache.commons.codec.digest.HmacUtils;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.wangsh.usersCenter.common.pojo.ApiResponse;
import com.wangsh.usersCenter.common.pojo.ApiResponseEnum;
import com.wangsh.usersCenter.common.service.BaseServiceImpl;
import com.wangsh.usersCenter.common.util.ConstatFinalUtil;
import com.wangsh.usersCenter.common.util.PageInfoUtil;
import com.wangsh.usersCenter.outer.service.IServerOuterService;
import com.wangsh.usersCenter.system.pojo.ACate;
import com.wangsh.usersCenter.system.pojo.ACateEnum;
import com.wangsh.usersCenter.system.pojo.ARegion;
import com.wangsh.usersCenter.system.pojo.ARegionEnum;
import com.wangsh.usersCenter.system.service.ISystemDbService;
import com.wangsh.usersCenter.users.pojo.AAdmins;
import com.wangsh.usersCenter.users.pojo.AUsers;
import com.wangsh.usersCenter.users.pojo.AUsersApis;
import com.wangsh.usersCenter.users.service.INoLoginOperService;
import com.wangsh.usersCenter.users.service.IRbacDbService;
import com.wangsh.usersCenter.users.service.IUsersDbService;
import com.wangsh.usersCenter.users.service.IUsersOperService;

/**
 * 用户不需要登陆的一些操作
 * 
 * @author wangsh
 * @param <T>
 */
@Service("serverOuterService")
public class ServerOuterServiceImpl<T> extends BaseServiceImpl implements IServerOuterService
{
	@Resource
	private ISystemDbService systemDbService;
	@Resource
	private IUsersOperService usersOperService;
	@Resource
	private IUsersDbService usersDbService;
	@Resource
	private IRbacDbService rbacDbService;
	
	@Resource
	private INoLoginOperService noLoginOperService ; 
	
	/**
	 * 系统之间的加密验证(私钥)
	 * 加密字符串:version + pubKey + time, HmacUtils.hmacMd5Hex("私钥", "加密字符串"); 
	 * 公钥随便传;只要私钥正确就可以
	 * @param reqJSON
	 * @return
	 */
	private ApiResponse<Object> verifyEncryptStr(JSONObject reqJSON)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		String version = reqJSON.getString("version");
		String pubKey = reqJSON.getString("pubKey");
		String time = reqJSON.getString("time");
		String encryptStr = reqJSON.getString("encrypt");

		/*
		 * 为了安全,私钥不能从请求中获取,读取本地的配置文件 私钥:客户端和服务器端同时存储到配置文件中
		 */
		// priKey=abc
		String priKey = ConstatFinalUtil.CONFIG_JSON.getString("usersCenter.out.prikey");
		/* 加密源字符串 */
		String souStr = version + pubKey + time ; 
		/* 验证加密字符串 */
		//String encHou = DigestUtils.sha256Hex(version + pubKey + time);
		/* sha256,key加密 */
		HmacUtils hmacUtils = new HmacUtils(HmacAlgorithms.HMAC_SHA_256, priKey);
		/* 加密 */
		String encHou = hmacUtils.hmacHex(souStr);
		
		if (encHou.equalsIgnoreCase(encryptStr)
				|| "0".equalsIgnoreCase(ConstatFinalUtil.CONFIG_JSON.getString("version")))
		{
			/* 成功 */
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			/* 请求非法,您在恶意攻击 */
			apiResponse.setCode(ApiResponseEnum.INFO_JSON_ATTACK.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	/**
	 * 验证用户的公钥和私钥
	 * 
	 * 加密字符串:version + pubKey + time, HmacUtils.hmacMd5Hex("私钥", "加密字符串"); 
	 * @return
	 */
	private ApiResponse<Object> verifyEncryptUsersStr(JSONObject reqJSON)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		String version = reqJSON.getString("version");
		String pubKey = reqJSON.getString("pubKey");
		String time = reqJSON.getString("time");
		String encryptStr = reqJSON.getString("encrypt");
		
		if(pubKey == null)
		{
			pubKey = "" ; 
		}
		if("".equalsIgnoreCase(pubKey))
		{
			/* 请求非法,您在恶意攻击 */
			apiResponse.setCode(ApiResponseEnum.INFO_PUBKEY_ERROR.getStatus());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
			return apiResponse ; 
		}
		
		/* 存储数据 */
		Map<String, Object> dataMapJava = new HashMap<String, Object>();
		apiResponse.setDataMapJava(dataMapJava);
		
		Map<String, Object> condMap = new HashMap<String, Object>();

		/* 判断是正式版本还是测试版本 */
		/* 验证公钥 */
		/*
		 * 为了安全,私钥不能从请求中获取,读取本地的配置文件 私钥:客户端和服务器端同时存储到配置文件中
		 */
		/* 根据公钥查询数据库 */
		condMap.clear();
		condMap.put("pubKey", pubKey);
		ApiResponse<AUsersApis> usersApiResponse = this.usersDbService.findOneUsersApiService(condMap);
		/* 获取对象 */
		AUsersApis usersApis = usersApiResponse.getDataOneJava() ; 
		
		/* 存储数据 */
		dataMapJava.put("usersApis", usersApis);
		if(usersApis != null)
		{
			/* 私钥 */
			String priKey = usersApis.getPriKey() ;
			/* 加密源字符串 */
			String souStr = version + pubKey + time ; 
			/* 验证加密字符串 */
			//String encHou = DigestUtils.sha256Hex(version + pubKey + time);
			/* sha256,key加密 */
			HmacUtils hmacUtils = new HmacUtils(HmacAlgorithms.HMAC_SHA_256, priKey);
			/* 加密 */
			String encHou = hmacUtils.hmacHex(souStr);
			if (encHou.equalsIgnoreCase(encryptStr))
			{
				/* 成功 */
				apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			} else
			{
				/* 请求非法,您在恶意攻击 */
				apiResponse.setCode(ApiResponseEnum.INFO_SIGN_ERROR.getStatus());
			}
		}else
		{
			apiResponse.setCode(ApiResponseEnum.INFO_JSON_ATTACK.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}
	
	/**
	 * 创建分页对象
	 * @param dataReqJSON
	 * @return
	 */
	private PageInfoUtil proccedPageInfoUtil(JSONObject dataReqJSON)
	{
		/* 分页信息 */
		String pageFlag = dataReqJSON.getString("pageFlag");
		String currentPage = dataReqJSON.getString("currentPage");
		String pageSize = dataReqJSON.getString("pageSize");
		PageInfoUtil pageInfoUtil = null ; 
		if("1".equalsIgnoreCase(pageFlag))
		{
			pageInfoUtil = new PageInfoUtil();
			
			try
			{
				pageInfoUtil.setCurrentPage(Integer.valueOf(currentPage));
				pageInfoUtil.setPageSize(Integer.valueOf(pageSize));
			} catch (Exception e)
			{
			}
		}
		return pageInfoUtil ;
	}

	@Override
	public ApiResponse<Object> clientVersionService(JSONObject reqJSON)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--clientVersionService--");
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		String version = reqJSON.getString("version");
		String method = reqJSON.getString("method");
		if ("verifyUsersToken".equalsIgnoreCase(method))
		{
			if ("1".equalsIgnoreCase(version))
			{
				apiResponse = this.verifyUsers01Token(reqJSON);
			} else
			{
				apiResponse.setCode(ApiResponseEnum.INFO_JSON_VERSION_ERROR.getStatus());
			}
		} else if ("verifyAdminsToken".equalsIgnoreCase(method))
		{
			if ("1".equalsIgnoreCase(version))
			{
				apiResponse = this.verifyAdmins01Token(reqJSON);
			} else
			{
				apiResponse.setCode(ApiResponseEnum.INFO_JSON_VERSION_ERROR.getStatus());
			}
		} else if ("regionOne".equalsIgnoreCase(method))
		{
			if ("1".equalsIgnoreCase(version))
			{
				apiResponse = this.region01One(reqJSON);
			} else
			{
				apiResponse.setCode(ApiResponseEnum.INFO_JSON_VERSION_ERROR.getStatus());
			}
		} else if ("regionBatchOne".equalsIgnoreCase(method))
		{
			if ("1".equalsIgnoreCase(version))
			{
				apiResponse = this.region01BatchOne(reqJSON);
			} else
			{
				apiResponse.setCode(ApiResponseEnum.INFO_JSON_VERSION_ERROR.getStatus());
			}
		}else if ("regionList".equalsIgnoreCase(method))
		{
			if ("1".equalsIgnoreCase(version))
			{
				apiResponse = this.region01List(reqJSON);
			} else
			{
				apiResponse.setCode(ApiResponseEnum.INFO_JSON_VERSION_ERROR.getStatus());
			}
		} else if ("cateList".equalsIgnoreCase(method))
		{
			if ("1".equalsIgnoreCase(version))
			{
				apiResponse = this.cate01List(reqJSON);
			} else
			{
				apiResponse.setCode(ApiResponseEnum.INFO_JSON_VERSION_ERROR.getStatus());
			}
		} else if ("cateBatchOne".equalsIgnoreCase(method))
		{
			if ("1".equalsIgnoreCase(version))
			{
				apiResponse = this.cate01BatchOne(reqJSON);
			} else
			{
				apiResponse.setCode(ApiResponseEnum.INFO_JSON_VERSION_ERROR.getStatus());
			}
		} else if ("cateOne".equalsIgnoreCase(method))
		{
			if ("1".equalsIgnoreCase(version))
			{
				apiResponse = this.cate01One(reqJSON);
			} else
			{
				apiResponse.setCode(ApiResponseEnum.INFO_JSON_VERSION_ERROR.getStatus());
			}
		} else if ("usersInfo".equalsIgnoreCase(method))
		{
			if ("1".equalsIgnoreCase(version))
			{
				apiResponse = this.usersInfo01One(reqJSON);
			} else
			{
				apiResponse.setCode(ApiResponseEnum.INFO_JSON_VERSION_ERROR.getStatus());
			}
		} else if ("verifyAdminsAuth".equalsIgnoreCase(method))
		{
			if ("1".equalsIgnoreCase(version))
			{
				apiResponse = this.verifyAdmins01Auth(reqJSON);
			} else
			{
				apiResponse.setCode(ApiResponseEnum.INFO_JSON_VERSION_ERROR.getStatus());
			}
		} else if ("getRoleMenu".equalsIgnoreCase(method))
		{
			if ("1".equalsIgnoreCase(version))
			{
				apiResponse = this.getRole01Menu(reqJSON);
			} else
			{
				apiResponse.setCode(ApiResponseEnum.INFO_JSON_VERSION_ERROR.getStatus());
			}
		} else
		{
			apiResponse.setCode(ApiResponseEnum.INFO_METHOD_ERROR.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		/* 提示信息 */
		return apiResponse;
	}
	
	/**
	 * 查询用户信息
	 * @param reqJSON
	 * @return
	 */
	public ApiResponse<Object> usersInfo01One(JSONObject reqJSON)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--usersInfo--");
		/* 验证请求的合法性 */
		ApiResponse<Object> apiResponse = this.verifyEncryptUsersStr(reqJSON);
		
		/* 存储多个结果,Map存储 */
		Map<String, Object> dataMapJava = apiResponse.getDataMapJava() ; 
		/* 获取用户信息 */
		AUsersApis usersApis = (AUsersApis) dataMapJava.get("usersApis");
		if (apiResponse.getCode() != ApiResponseEnum.STATUS_SUCCESS.getStatus())
		{
			apiResponse.setDataMapJava(Collections.EMPTY_MAP);
			return apiResponse;
		}
		/* 清空数据 */
		apiResponse.setDataMapJava(Collections.EMPTY_MAP);
		/* 存储单个对象 */
		Map<String, Object> dataOneMap = new HashMap<String, Object>();
		apiResponse.setDataOne(dataOneMap);
		
		AUsers users = usersApis.getUsers() ; 
		/* 返回用户的相关信息 */
		dataOneMap.put(ApiResponseEnum.NAME_ONE.getName(), users);
		/* ----生成Token:服务端认的只有Token----
		 * 存储到redis,保存3分钟 */
		this.noLoginOperService.operAddUsersTokenService(users);
		String token = users.getTokenStr() ; 
		dataOneMap.put("token", token);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		/* 提示信息 */
		return apiResponse;
	}

	/**
	 * 验证用户的Token
	 * 
	 * @param reqJSON
	 * @return
	 */
	public ApiResponse<Object> verifyUsers01Token(JSONObject reqJSON)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--verifyUsers01Token--");
		Map<String, Object> condMap = new HashMap<String, Object>();
		/* 验证请求的合法性 */
		ApiResponse<Object> apiResponse = this.verifyEncryptStr(reqJSON);
		if (apiResponse.getCode() != ApiResponseEnum.STATUS_SUCCESS.getStatus())
		{
			return apiResponse;
		}
		
		/* 存储多个结果,Map存储 */
		Map<String, Object> dataMapJava = new HashMap<String, Object>();
		apiResponse.setDataMapJava(dataMapJava);

		Map<String, Object> dataOneMap = new HashMap<String, Object>();
		apiResponse.setDataOne(dataOneMap);

		/* 接收参数 */
		JSONObject dataReqJSON = (JSONObject) reqJSON.get("data");
		String token = dataReqJSON.get("token") + "";

		String key = redisUtil.KEY_USERS_TOKEN + token;
		String json = this.redisUtil.get(key) + "";
		JSONObject usersJSON = (JSONObject) JSON.parse(json);
		if (usersJSON != null)
		{
			/* 重新查询一下用户的信息,然后再放进去 */
			String id = usersJSON.getString("id");
			
			condMap.clear();
			condMap.put("id", id);
			ApiResponse<AUsers> usersApiResponse = this.usersDbService.findOneUsersService(condMap);
			AUsers users = usersApiResponse.getDataOneJava() ;
			/* 存储token */
			users.setTokenStr(token);
			/* 转换成json */
			usersJSON = users.toJSON() ; 
			json = usersJSON.toJSONString() ; 
			
			/* 重新再放一次 timeout.token=60 */
			this.redisUtil.put(key, json, Integer.valueOf(ConstatFinalUtil.CONFIG_JSON.getString("timeout.token")));
			/* 用户相关的JSON */
			dataOneMap.put("users", usersJSON);
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.INFO_LOGIN_ILLEGAL.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		/* 提示信息 */
		return apiResponse;
	}

	/**
	 * 验证管理员的Token
	 * 
	 * @param reqJSON
	 * @return
	 */
	private ApiResponse<Object> verifyAdmins01Token(JSONObject reqJSON)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--verifyAdminsToken--");
		Map<String, Object> condMap = new HashMap<String, Object>();
		/* 验证请求的合法性 */
		ApiResponse<Object> apiResponse = this.verifyEncryptStr(reqJSON);
		if (apiResponse.getCode() != ApiResponseEnum.STATUS_SUCCESS.getStatus())
		{
			return apiResponse;
		}
		/* 存储多个结果,Map存储 */
		Map<String, Object> dataMapJava = new HashMap<String, Object>();
		apiResponse.setDataMapJava(dataMapJava);
		Map<String, Object> dataOneMap = new HashMap<String, Object>();
		apiResponse.setDataOne(dataOneMap);
		/* 接收参数 */
		JSONObject dataReqJSON = (JSONObject) reqJSON.get("data");
		String token = dataReqJSON.get("token") + "";
		String key = redisUtil.KEY_ADMINS_TOKEN + token;
		String json = this.redisUtil.get(key) + "";
		JSONObject adminsJSON = (JSONObject) JSON.parse(json);
		if (adminsJSON != null)
		{
			ConstatFinalUtil.SYS_LOGGER.info("许昌请求redis:"+adminsJSON.toString());
			
			String id = adminsJSON.getString("id");
			
			condMap.clear();
			condMap.put("id", id);
			ApiResponse<AAdmins> adminsApiResponse = this.usersDbService.findOneAdminsService(condMap);
			AAdmins admins = adminsApiResponse.getDataOneJava() ;
			/* 存储token */
			admins.setTokenStr(token);
			/* 转换成json */
			adminsJSON = admins.toJSON() ; 
			json = adminsJSON.toJSONString() ; 
			
			/* 重新再放一次 */
			this.redisUtil.put(key, json, Integer.valueOf(ConstatFinalUtil.CONFIG_JSON.getString("timeout.token")));
			/* 用户相关的JSON */
			dataOneMap.put("admins", adminsJSON);
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.INFO_LOGIN_ILLEGAL.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		/* 提示信息 */
		return apiResponse;
	}

	/**
	 * 查询单条记录
	 * 
	 * @param reqJSON
	 * @return
	 */
	public ApiResponse<Object> region01One(JSONObject reqJSON)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--region01One--");
		/* 验证请求的合法性 */
		ApiResponse<Object> apiResponse = this.verifyEncryptStr(reqJSON);
		if (apiResponse.getCode() != ApiResponseEnum.STATUS_SUCCESS.getStatus())
		{
			return apiResponse;
		}
		/* 存储多个结果,Map存储 */
		Map<String, Object> dataMapJava = new HashMap<String, Object>();
		apiResponse.setDataMapJava(dataMapJava);

		Map<String, Object> dataOneMap = new HashMap<String, Object>();
		apiResponse.setDataOne(dataOneMap);

		/* 接收参数 */
		JSONObject dataReqJSON = (JSONObject) reqJSON.get("data");
		String id = dataReqJSON.get("id") + "";

		/* 查询数据 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		/* 查询当前的节点 */
		condMap.clear();
		condMap.put("id", id);
		ApiResponse<ARegion> apiRes = this.systemDbService.findOneRegionService(condMap);

		ARegion region = apiRes.getDataOneJava();
		dataOneMap.put(ApiResponseEnum.NAME_ONE.getName(), region);
		/* 提示信息 */
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	/**
	 * 按照查询查询地区(批量查询多个) 
	 * 上行参数为: data:{"ids":[1,1,2,3,]}
	 * @param reqJSON
	 * @return
	 */
	private ApiResponse<Object> region01BatchOne(JSONObject reqJSON)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--region01BatchOne--");
		/* 验证请求的合法性 */
		ApiResponse<Object> apiResponse = this.verifyEncryptStr(reqJSON);
		if (apiResponse.getCode() != ApiResponseEnum.STATUS_SUCCESS.getStatus())
		{
			return apiResponse;
		}
		Map<String, List<Object>> dataList = new HashMap<String, List<Object>>();
		apiResponse.setDataList(dataList);

		/* 接收参数 */
		JSONObject dataReqJSON = (JSONObject) reqJSON.get("data");
		JSONArray idsArr = (JSONArray) dataReqJSON.get("ids");

		/* 查询数据 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		/* 查询当前的节点 */
		condMap.clear();
		condMap.put("ids", idsArr);
		condMap.put("status", ARegionEnum.STATUS_ENABLE.getStatus() + "");
		condMap.put("extend", "true");
		ApiResponse<ARegion> apiRes = this.systemDbService.findCondListRegionService(null, condMap);
		/* 地区列表 */
		List regionList = apiRes.getDataListJava();
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), regionList);

		apiResponse.setDataList(dataList);

		/* 提示信息 */
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}
	
	/**
	 * 查询列表
	 * @param reqJSON
	 * @return
	 */
	private ApiResponse<Object> region01List(JSONObject reqJSON)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--region01List--");
		/* 验证请求的合法性 */
		ApiResponse<Object> apiResponse = this.verifyEncryptStr(reqJSON);
		if (apiResponse.getCode() != ApiResponseEnum.STATUS_SUCCESS.getStatus())
		{
			return apiResponse;
		}
		Map<String, List<Object>> dataList = new HashMap<String, List<Object>>();
		apiResponse.setDataList(dataList);

		/* 接收参数 */
		JSONObject dataReqJSON = (JSONObject) reqJSON.get("data");
		String parentId = dataReqJSON.getString("parentId");
		/* 根据上行参数生成分页信息 */
		PageInfoUtil pageInfoUtil = proccedPageInfoUtil(dataReqJSON);
		
		/* 查询数据 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		/* 查询当前的节点 */
		condMap.clear();
		condMap.put("parentId", parentId);
		condMap.put("status", ARegionEnum.STATUS_ENABLE.getStatus() + "");
		ApiResponse<ARegion> apiRes = this.systemDbService.findCondListRegionService(pageInfoUtil, condMap);
		/* 地区列表 */
		List regionList = apiRes.getDataListJava();
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), regionList);

		apiResponse.setDataList(dataList);
		/* 向接口中放分页信息 */
		apiResponse.setPageInfoUtil(pageInfoUtil);

		/* 提示信息 */
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	/**
	 * 查询所有的分类列表
	 * 
	 * @param reqJSON
	 * @return
	 */
	private ApiResponse<Object> cate01List(JSONObject reqJSON)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--cate01List--");
		/* 验证请求的合法性 */
		ApiResponse<Object> apiResponse = this.verifyEncryptStr(reqJSON);
		if (apiResponse.getCode() != ApiResponseEnum.STATUS_SUCCESS.getStatus())
		{
			return apiResponse;
		}
		Map<String, List<Object>> dataList = new HashMap<String, List<Object>>();
		apiResponse.setDataList(dataList);
		/* 存储多个结果,Map存储 */

		/* 接收参数 */
		JSONObject dataReqJSON = (JSONObject) reqJSON.get("data");
		String parentId = dataReqJSON.get("parentId") + "";
		String cateType = dataReqJSON.get("cateType") + "";
		
		/* 根据上行参数生成分页信息 */
		PageInfoUtil pageInfoUtil = proccedPageInfoUtil(dataReqJSON);

		/* 查询数据 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		/* 查询当前的节点 */
		condMap.clear();
		condMap.put("parentId", parentId);
		condMap.put("cateType", cateType);
		condMap.put("status", ACateEnum.STATUS_ENABLE.getStatus());
		ApiResponse<ACate> apiRes = this.systemDbService.findCondListCateService(pageInfoUtil, condMap);
		/* 地区列表 */
		List regionList = apiRes.getDataListJava();
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), regionList);

		apiResponse.setDataList(dataList);
		/* 向接口中放分页信息 */
		apiResponse.setPageInfoUtil(pageInfoUtil);

		/* 提示信息 */
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}
	
	/**
	 * 查询单条记录
	 * 
	 * @param reqJSON
	 * @return
	 */
	public ApiResponse<Object> cate01One(JSONObject reqJSON)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--cate01One--");
		/* 验证请求的合法性 */
		ApiResponse<Object> apiResponse = this.verifyEncryptStr(reqJSON);
		if (apiResponse.getCode() != ApiResponseEnum.STATUS_SUCCESS.getStatus())
		{
			return apiResponse;
		}
		/* 存储多个结果,Map存储 */
		Map<String, Object> dataMapJava = new HashMap<String, Object>();
		apiResponse.setDataMapJava(dataMapJava);

		Map<String, Object> dataOneMap = new HashMap<String, Object>();
		apiResponse.setDataOne(dataOneMap);

		/* 接收参数 */
		JSONObject dataReqJSON = (JSONObject) reqJSON.get("data");
		String id = dataReqJSON.get("id") + "";

		/* 查询数据 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		/* 查询当前的节点 */
		condMap.clear();
		condMap.put("id", id);
		ApiResponse<ACate> apiRes = this.systemDbService.findOneCateService(condMap);

		ACate cate = apiRes.getDataOneJava();
		dataOneMap.put(ApiResponseEnum.NAME_ONE.getName(), cate);
		/* 提示信息 */
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	/**
	 * 批量查询多个分类 上行参数为: data:{"ids":[1,1,2,3,]}
	 * 
	 * @param reqJSON
	 * @return
	 */
	private ApiResponse<Object> cate01BatchOne(JSONObject reqJSON)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--cate01BatchOne--");
		/* 验证请求的合法性 */
		ApiResponse<Object> apiResponse = this.verifyEncryptStr(reqJSON);
		if (apiResponse.getCode() != ApiResponseEnum.STATUS_SUCCESS.getStatus())
		{
			return apiResponse;
		}
		Map<String, List<Object>> dataList = new HashMap<String, List<Object>>();
		apiResponse.setDataList(dataList);

		/* 接收参数 */
		JSONObject dataReqJSON = (JSONObject) reqJSON.get("data");
		JSONArray idsArr = (JSONArray) dataReqJSON.get("ids");

		/* 查询数据 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		/* 查询当前的节点 */
		condMap.clear();
		condMap.put("ids", idsArr);
		condMap.put("extend", "true");
		ApiResponse<ACate> apiRes = this.systemDbService.findCondListCateService(null, condMap);
		/* 分类列表 */
		List cateList = apiRes.getDataListJava();
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), cateList);

		apiResponse.setDataList(dataList);

		/* 提示信息 */
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	/**
	 * 验证当前管理员,是否有权限访问当前的网页;
	 * 
	 * @param reqJSON
	 * @return
	 */
	public ApiResponse<Object> verifyAdmins01Auth(JSONObject reqJSON)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--verifyAdmins01Auth--");
		/* 验证请求的合法性 */
		ApiResponse<Object> apiResponse = this.verifyEncryptStr(reqJSON);
		if (apiResponse.getCode() != ApiResponseEnum.STATUS_SUCCESS.getStatus())
		{
			return apiResponse;
		}
		/* 存储多个结果,Map存储 */
		Map<String, Object> dataMapJava = new HashMap<String, Object>();
		apiResponse.setDataMapJava(dataMapJava);

		Map<String, Object> dataOneMap = new HashMap<String, Object>();
		apiResponse.setDataOne(dataOneMap);

		/* 接收参数 */
		JSONObject dataReqJSON = (JSONObject) reqJSON.get("data");
		String adminsId = dataReqJSON.get("adminsId") + "";
		String currentUrl = dataReqJSON.get("currentUrl") + "";

		/*
		 * ~根据用户查询角色 ~根据角色id和查询角色和菜单表
		 */
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		paramsMap.put("adminsId", adminsId);
		paramsMap.put("currentUrl", currentUrl);
		apiResponse = this.usersOperService.verifyAdminsAuthSerivce(paramsMap);

		/* 提示信息 */
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	/**
	 * 获取角色所拥有的菜单;
	 * 
	 * @param reqJSON
	 * @return
	 */
	private ApiResponse<Object> getRole01Menu(JSONObject reqJSON)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--getRole01Menu--");
		/* 验证请求的合法性 */
		ApiResponse<Object> apiResponse = this.verifyEncryptStr(reqJSON);
		if (apiResponse.getCode() != ApiResponseEnum.STATUS_SUCCESS.getStatus())
		{
			return apiResponse;
		}
		/* 存储多个结果,Map存储 */
		Map<String, Object> dataMapJava = new HashMap<String, Object>();
		apiResponse.setDataMapJava(dataMapJava);

		Map<String, Object> dataOneMap = new HashMap<String, Object>();
		apiResponse.setDataOne(dataOneMap);

		/* 接收参数 */
		JSONObject dataReqJSON = (JSONObject) reqJSON.get("data");
		String adminsId = dataReqJSON.get("adminsId") + "";
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		paramsMap.put("id", adminsId);
		ApiResponse<AAdmins> findOneAdminsService = this.usersDbService.findOneAdminsService(paramsMap);
		AAdmins dataOneJava = findOneAdminsService.getDataOneJava();
		int roleId = dataOneJava.getRoleId();
		paramsMap.clear();
		paramsMap.put("roleId", roleId + "");
		apiResponse = this.usersOperService.getRoleMenuSerivce(paramsMap);
		/* 提示信息 */
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);

		return apiResponse;
	}
}
